home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part2 / 10725 < prev    next >
Encoding:
Text File  |  1996-08-05  |  1.7 KB  |  53 lines

  1. Newsgroups: comp.lang.c++
  2. Path: id.dtu.dk!news!jl
  3. From: jl@id.dth.dk (J°rn Lind-Nielsen)
  4. Subject: Output to file vs. cout
  5. Message-ID: <JL.96Mar7165152@thyme.id.dth.dk>
  6. Sender: news@id.dtu.dk (NetNews)
  7. Organization: Department of Computer Science, The Technical University of
  8.     Denmark
  9. Distribution: comp
  10. Date: Thu, 7 Mar 1996 21:51:52 GMT
  11.  
  12.  
  13. Here's another of the probs that comes from porting C to C++:
  14.  
  15. - I want to be able to redirect program output to either a file or cout.
  16.   Typically this would be selected by a commandline option ("-o outfile").
  17.  
  18. - In C I would do something like this:
  19.  
  20.  
  21.      main()
  22.      {
  23.        FILE *outputfile;
  24.  
  25.        if (commandline == do_output_to_file)
  26.           outputfile = stdout;
  27.        else
  28.           outputfile = fopen(passed_filename, "w");
  29.  
  30.        fprintf(outfile, "Hello world\n");
  31.  
  32.        fclose(outfile);  /* Maybe - not allways necassary */
  33.      }
  34.  
  35.  
  36.  
  37. - The question is:  How is this done in C++ ?
  38.  
  39.  
  40. ------------------------------------------------------------------------
  41. From:    Jorn Bo Lind-Nielsen     /"""\    Bergsoe Kollegiet 2104
  42. E-mail:  jl@it.dtu.dk             |o o|    DK - 2850 Naerum
  43. --------------------------------ooo-U-ooo-------------------------------
  44. A Norton Commander for Unix ?              FTP duroc.ds-data.dk /pub/uc
  45. ------------------------------------------------------------------------
  46. --
  47. ------------------------------------------------------------------------
  48. From:    Jorn Bo Lind-Nielsen     /"""\    Bergsoe Kollegiet 2104
  49. E-mail:  jl@it.dtu.dk             |o o|    DK - 2850 Naerum
  50. --------------------------------ooo-U-ooo-------------------------------
  51. A Norton Commander for Unix ?              FTP duroc.ds-data.dk /pub/uc
  52. ------------------------------------------------------------------------
  53.